package com.example.wo.jsbapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.EditText;
import android.widget.ListView;

import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ListView listView;
    private List<Note> notes;
    private EditText edtTitle,edtContent;
    private  Note note;
    private NoteDao noteDao;
    private NoteAdapter noteAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initNote();
        noteDao= new NoteDao(MainActivity.this);
        notes= noteDao.getAll();
         noteAdapter= new NoteAdapter(this,notes);
        listView.setAdapter(noteAdapter);
    }

    private void initNote() {
        listView =findViewById(R.id.list_view);
        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Note note = (Note) parent.getItemAtPosition(position);
            }
        });
    }
    public void add(View view){
        edtTitle = findViewById(R.id.edt_title);
       edtContent =findViewById(R.id.edt_content);
      String title =edtTitle.getText().toString();
        String content = edtContent.getText().toString();
        note = new Note(null,title,content);
        noteDao.insert(note);
        notes = noteDao.getAll();
        noteAdapter.setData(notes);
    }
}
